/**
 * xml字符串转对象
 * @param {String} str XML字符串
 */
export const createXml = function(str) {
  var xml = null
  try {
    xml = new DOMParser().parseFromString(str, 'text/xml')
  } catch (e) {
    xml = new ActiveXObject('Microsoft.XMLDOM')
    xml.async = false
    xml.loadXML(str)
  }
  return xml
}

/**
 * 获取xml根元素的Text
 * @param {XMLDocument} xmlStr XML内容
 */
export const rootVal = function(xmlStr) {
  var xml = createXml(xmlStr)
  if (xml.hasChildNodes()) {
    let item = xml.childNodes.item(0)
    return item.textContent.replace(/\\/g, '\\\\')
  }
  return ''
}